/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.unitn.science.matr155863_148346_145963.bccastestore.items;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 *
 * @author berto
 */
public class User implements Serializable{
    
    public static final String ID="_id_user";
    public static final String PASSWORD="password";
    public static final String EMAIL="email";
    public static final String FIRST_NAME="first_name";
    public static final String LAST_NAME="last_name";
    public static final String BIRTHDATE="birthdate";
    public static final String STATUS="status";
    public static final String REGISTER_AT=("register_at");
    public static final String USERNAME="username";
    public static final String ADDRESS="address";

    private String email;
    private String username;
    private String password;
    private String first_name;
    private String last_name;
    private Date birthdate;
    private Integer status;
    private Date register_at;
    private Integer id;
    private String address;

    public User(){
    }

    public User(String email, String username, String password,
            String first_name, String last_name, Long birthdate, 
            String address, Integer status, Integer id, Long register_at) {
        this.email=email;
        this.username=username;
        this.password=password;
        this.first_name=first_name;
        this.last_name=last_name;
        this.birthdate=new Date(birthdate);
        this.address=address;
        this.status=status;
        this.id=id;
        this.register_at=new Date(register_at);
    }

    public Date getRegister_at() {
        return register_at;
    }

    public void setRegister_at(Date register_at) {
        this.register_at = register_at;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }
    
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
    
    

    public void setBirthdate(Date birthdate) {
        this.birthdate = birthdate;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setFirst_name(String first_name) {
        this.first_name = first_name;
    }

    public void setLast_name(String last_name) {
        this.last_name = last_name;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    
    
    /*public User(String string) throws ParseException {
        //email
        int index=string.indexOf(User.EXCAPE);
        email=string.substring(0,index);
        string=string.substring(index+1);
        
        //password
        index=string.indexOf(User.EXCAPE);
        email=string.substring(0,index);
        string=string.substring(index+1);
        
        //first_name
        index=string.indexOf(User.EXCAPE);
        first_name=string.substring(0,index);
        string=string.substring(index+1);
        
        //last_name
        index=string.indexOf(User.EXCAPE);
        last_name=string.substring(0,index);
        string=string.substring(index+1);
        
        //birthdate
        SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy",Locale.ITALIAN);
        sf.setLenient(false);
        index=string.indexOf(User.EXCAPE);
        birthdate=sf.parse(string.substring(0,index));
        string=string.substring(index+1);
        
        //weight
        index=string.indexOf(User.EXCAPE);
        weight=Float.parseFloat(string.substring(0,index));
        string=string.substring(index+1);
        
        //id
        index=string.indexOf(User.EXCAPE);
        String stringId=string.substring(0,index);
        if(stringId!=null){
            id=Integer.parseInt(stringId);
        }
    }*/
    
    public void setId(Integer id){
        this.id=id;
    }
    
    public Integer getId(){
        return id;
    }
    
    public String getEmail() {
        return email;
    }
    
    public Date getBirthdate() {
        return birthdate;
    }

    public String getBirthdateHuman() {
        SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy",Locale.ITALIAN);
        sf.setLenient(false);
        String humanDate=sf.format(birthdate);
        return humanDate;
    }
    
    public String getFirst_name() {
        return first_name;
    }

    public String getLast_name() {
        return last_name;
    }

    public String getPassword() {
        return password;
    }

    public Boolean isAdmin() {
        if(status==2){
            return true;
        }else{
            return false;
        }
    }    

    public Boolean isActive() {
        if(status<=0){
            return false;
        }else{
            return true;
        }
    }    
    
}
